﻿
// MFCApplication1View.cpp: CMFCApplication1View 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MFCApplication1.h"
#endif

#include "MFCApplication1Doc.h"
#include "MFCApplication1View.h"
#include "MyDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define IDB_STATIC 131
// CMFCApplication1View

IMPLEMENT_DYNCREATE(CMFCApplication1View, CView)

BEGIN_MESSAGE_MAP(CMFCApplication1View, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_COMMAND(ID_TOOL_DIALOG, &CMFCApplication1View::OnToolDialog)
END_MESSAGE_MAP()

// CMFCApplication1View 构造/析构

CMFCApplication1View::CMFCApplication1View() noexcept
{
	// TODO: 在此处添加构造代码

}

CMFCApplication1View::~CMFCApplication1View()
{
}

BOOL CMFCApplication1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CMFCApplication1View 绘图

void CMFCApplication1View::OnDraw(CDC* pDC)
{
	CMFCApplication1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	//提示信息
	pDC->TextOutW(10, 50, L"姓名：");
	pDC->TextOutW(10, 80, L"性别：");
	pDC->TextOutW(10, 110, L"年级：");
	pDC->TextOutW(10, 140, L"电话：");
	pDC->TextOutW(10, 170, L"爱好：");
	pDC->TextOutW(10, 200, L"身高：");
	pDC->TextOutW(10, 230, L"体重：");
	pDC->TextOutW(10, 260, L"生日：");
	pDC->TextOutW(10, 290, L"照片：");

	//显示名字
	pDC->TextOutW(70, 50, pDoc->m_name);
	//性别按bool存储，男：0  女：1 因此显示时需要判断
	CString sex;
	if (pDoc->m_sex == 0)
		sex = "男";
	else if (pDoc->m_sex == 1)
		sex = "女";
	pDC->TextOutW(70, 80, sex);
	//年级按int存，大一：1  大二：2  大三：3  大四：4  初始化为0
	CString grade;
	switch (pDoc->m_grade) {
	case 1:grade = "大一"; break;
	case 2:grade = "大二"; break;
	case 3:grade = "大三"; break;
	case 4:grade = "大四"; break;
	default:grade = ""; break;
	}
	pDC->TextOutW(70, 110, grade);
	//显示电话
	pDC->TextOutW(70, 140, pDoc->m_tel);
	//喜好用3bit表示，1XX表示喜欢足球，X1X表示喜欢篮球，XX1表示喜欢排球
	CString like("");
	if (pDoc->m_like >> 2 & 1)
		like += "足球";
	if (pDoc->m_like >> 1 & 1)
		like += " 篮球";
	if (pDoc->m_like & 1)
		like += " 排球";
	pDC->TextOutW(70, 170, like);
	//高度用int存，初始化为0
	CString height;
	if (pDoc->m_height > 140 && pDoc->m_height < 200)
		height.Format(L"%d", pDoc->m_height);
	pDC->TextOutW(70, 200, height);
	//体重同高度
	CString weight;
	if (pDoc->m_height > 40 && pDoc->m_weight < 100)
		weight.Format(L"%d", pDoc->m_weight);
	pDC->TextOutW(70, 230, weight);
	//生日用字符串存
	CString birthday;
	birthday = pDoc->m_birthday_str + "-" + pDoc->m_birthday_str2 + "-" + pDoc->m_birthday_str3;
	//birthday = pDoc->m_birthday.Format("%Y-%m-%d");
	pDC->TextOutW(70, 260, birthday);
	//pDC->TextOutW(70, 260, birthday);
	//图片按路径打开，因此用CString保存路径
	CString path = pDoc->m_bmp;
	//当路径不为空时
	if (path != "") {
		//因为bmp不能按路径打开，因此需要使用image，再转换为bmp
		CImage image;
		image.Load(path);
		CBitmap bmp;
		HBITMAP hbmp = image.Detach();
		bmp.DeleteObject();
		bmp.Attach(hbmp);
		//得到bmp后绘图
		CDC memDC;
		memDC.CreateCompatibleDC(pDC);
		memDC.SelectObject(&bmp);
		BITMAP info;
		bmp.GetBitmap(&info);
		//根据选择来确定图片尺寸，画刷填充图片
		pDC->StretchBlt(70, 290, 100, 140, &memDC, 0, 0, info.bmWidth, info.bmHeight, SRCCOPY);
	}
}

// CMFCApplication1View 打印

BOOL CMFCApplication1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CMFCApplication1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CMFCApplication1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}


// CMFCApplication1View 诊断

#ifdef _DEBUG
void CMFCApplication1View::AssertValid() const
{
	CView::AssertValid();
}

void CMFCApplication1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCApplication1Doc* CMFCApplication1View::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCApplication1Doc)));
	return (CMFCApplication1Doc*)m_pDocument;
}
#endif //_DEBUG


// CMFCApplication1View 消息处理程序


void CMFCApplication1View::OnToolDialog()
{
	//点击工具栏选项，弹出非模态对话框
	MyDialog* pDlg;
	pDlg = new MyDialog(this);
	pDlg->Create(IDD_DIALOG1);
	pDlg->ShowWindow(SW_SHOW);
}
